package com.esri.core.internal.io.handler;

import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

/* loaded from: classes.dex */
public class m {
    public static SSLContext a() throws IOException {
        try {
            SSLContext sSLContext = SSLContext.getInstance("TLS");
            sSLContext.init(null, new TrustManager[]{new f(null)}, null);
            return sSLContext;
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }

    public static SSLContext a(KeyStore keyStore, String str, KeyStore keyStore2) throws IOException {
        KeyManager[] a;
        if (keyStore != null) {
            try {
                a = a(keyStore, str);
            } catch (Exception e) {
                throw new IOException(e.getMessage());
            }
        } else {
            a = null;
        }
        TrustManager[] a2 = a(keyStore2);
        SSLContext sSLContext = SSLContext.getInstance("TLS");
        sSLContext.init(a, a2, null);
        return sSLContext;
    }

    private static KeyManager[] a(KeyStore keyStore, String str) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
        if (keyStore == null) {
            throw new IllegalArgumentException("Keystore may not be null");
        }
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(keyStore, str != null ? str.toCharArray() : null);
        return keyManagerFactory.getKeyManagers();
    }

    private static TrustManager[] a(KeyStore keyStore) throws KeyStoreException, NoSuchAlgorithmException {
        return new TrustManager[]{new f(keyStore)};
    }
}
